<template>
	<view>
		<view class="icon">
			<image src="/static/success.png"></image>
		</view>
		<view class="tis">
			订单支付成功
		</view>
		<view class="pay-amount">
			支付金额:{{amount}}元
		</view>
		<view class="back">
			<view class="btn" @tap="toIndex">{{content}}</view>
		</view>
	</view>
</template>

<script>
	let app = getApp()
	var that; // 当前页面对象
	var vk; // vk依赖
	export default {
		data() {
			return {
				amount: 0,
				type: 0 // 支付类型 0：默认返回首页 1：购买课程 2：充值学习币
			};
		},
		onLoad(e) {
			vk = this.vk;
			this.amount = parseFloat(e.amount).toFixed(2);
			this.type = Number(e.type)
		},
		onShow: function() {
			//支付完成返回，开始处理数据
			if (app.globalData.payStatus != null && app.globalData.payStatus != undefined) {
				let orderno = app.globalData.orderNo;
				console.log('接收到返回支付结果', app.globalData.payStatus);
				console.log('订单号', orderno);
				//处理您自己的业务
			}
		},
		computed: {
			content() {
				switch (this.type) {
					case 1:
						return '前往我的课程'
					case 2:
						return '返回我的账户'
					default:
						return '返回首页'
				}
			}
		},
		methods: {
			toIndex() {
				let url = '/pages/index/homePage'
				switch (this.type) {
					case 1:
						url = '/pages/mine/my-course/index'
						break
					case 2:
						url = '/pages/mine/account/study-coins'
						break
				}
				vk.redirectTo(url)
			}
		},
	}
</script>

<style lang="scss">
	view {
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
	}

	.icon {
		width: 100%;
		margin-top: 10vw;

		image {
			width: 25vw;
			height: 25vw;
		}
	}

	.tis {
		width: 100%;
		margin-top: 20upx;
		font-size: 48upx;
	}

	.pay-amount {
		width: 100%;
		margin-top: 10upx;
		font-size: 32upx;
	}

	.back {
		position: absolute;
		width: 100%;
		bottom: 80upx;

		.btn {
			padding: 0 50upx;
			height: 70upx;
			border: solid 2upx #025BFF;
			color: #025BFF;
			align-items: center;
			border-radius: 10upx;
			font-size: 34upx;
		}
	}
</style>
